package ro.msg.quiz.view;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

/**
 * Create the panel.
 * 
 * @author Adorjan
 */
public class AddQuestionStepTwoPanel extends JPanel {
	private int answerNo = 0;
	private int qType = -1;
	private final JPanel panel = new JPanel();
	private final JScrollPane scrollPane = new JScrollPane(panel);
	private final JTextField[] answerText;
	private JRadioButton[] answerRadio;
	private JCheckBox[] answerCheck;

	/**
	 * The panel's constructor
	 * 
	 * @param qType
	 * @param answerNo
	 * 
	 * @author Adorjan
	 */
	public AddQuestionStepTwoPanel(int qType, int answerNo) {
		setLayout(null);

		this.answerNo = answerNo;
		this.qType = qType;

		JLabel lblEditAnswers = new JLabel("Edit possible answers");
		lblEditAnswers.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblEditAnswers.setBounds(25, 24, 115, 15);
		add(lblEditAnswers);

		panel.setLayout(new FlowLayout());
		panel.setPreferredSize(new Dimension(190, answerNo * 30));

		scrollPane.setBounds(25, 57, 238, 160);
		add(scrollPane);

		answerText = new JTextField[this.answerNo];
		for (int i = 0; i < this.answerNo; i++) {
			answerText[i] = new JTextField();
			answerText[i].setPreferredSize(new Dimension(180, 20));
		}

		switch (qType) {
		// single choice
		case 0:
			ButtonGroup group = new ButtonGroup();
			answerRadio = new JRadioButton[this.answerNo];
			for (int i = 0; i < this.answerNo; i++) {
				answerRadio[i] = new JRadioButton();
				group.add(answerRadio[i]);
				panel.add(answerRadio[i]);
				panel.add(answerText[i]);
			}
			break;
		// multiple choice
		case 1:
			answerCheck = new JCheckBox[this.answerNo];
			for (int i = 0; i < this.answerNo; i++) {
				answerCheck[i] = new JCheckBox();
				panel.add(answerCheck[i]);
				panel.add(answerText[i]);
			}
			break;
		// text
		case 2:
			panel.add(answerText[0]);
			break;
		}

	}

	/**
	 * @return the answerText
	 */
	public JTextField[] getAnswerText() {
		return answerText;
	}

	/**
	 * @return the answerRadio
	 */
	public JRadioButton[] getAnswerRadio() {
		return answerRadio;
	}

	/**
	 * @return the answerCheck
	 */
	public JCheckBox[] getAnswerCheck() {
		return answerCheck;
	}
}
